"""

@File:ego_index_api.py
@Datetime:2022/11/12 23:26
@Author:wangt
@Desc:
"""
import logging

import requests

from config import BASE_URL


# 封装首页接口测试类
class EgoIndexApi(object):

    # 定义初始化方法（作用：定义实例化之后的对象的属性）
    def __init__(self):
        self.banner_url = f"{BASE_URL}/api/v1/banner/"
        self.theme_url = f"{BASE_URL}/api/v1/theme"
        self.pro_recent_url = f"{BASE_URL}/api/v1/product/recent"

    # 获取轮播图
    def ego_banner(self, banner_id):
        new_url = f"{self.banner_url}{banner_id}"
        # url = f"{BASE_URL}/api/v1/banner/{target}"
        resp = requests.get(new_url)
        return resp

    # 获取专题栏位
    def ego_theme(self, ids):
        # url = f"{BASE_URL}/api/v1/theme?ids={ids}"
        data = {"ids": ids}
        resp = requests.get(self.theme_url, params=data)  # 注意：get方法用params传入参数
        return resp

    # 获取最近新品
    def ego_pro_recent(self):
        # url = f"{BASE_URL}/api/v1/product/recent"
        resp = requests.get(self.pro_recent_url)
        return resp


if __name__ == '__main__':
    ei = EgoIndexApi()
    # resp = ei.ego_banner(1)
    # print(resp.text)
    # ids = "1,2,3"
    # resp = ei.ego_theme(ids)
    resp = ei.ego_pro_recent()
    print(resp.json())
